import { BrowserModule } from '@angular/platform-browser';
import { APP_INITIALIZER, NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { RouterModule, Routes } from '@angular/router';
import { MstRouterModule } from 'mstcomponents/router';
import {
  StartUpService,
  StartupServiceFactory,
} from './services/start.service';

const route: Routes = [
  {
    path: '',
    redirectTo: '/demo',
    pathMatch: 'full',
  },
  {
    path: 'demo',
    loadChildren: () =>
      import('./demo/demo.module').then((m) => m.MstDemoModule),
  },
  {
    path: 'pagedemo',
    loadChildren: () =>
      import('./pagedemo/pagedemo.module').then((m) => m.MstPageDemoModule),
  },
];

const START_UP = [
  StartUpService,
  {
    provide: APP_INITIALIZER,
    useFactory: StartupServiceFactory,
    deps: [StartUpService],
    multi: true,
  },
];

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    RouterModule.forRoot(route),
    MstRouterModule.forReuseStrategy({ iframe: false }),
  ],
  providers: [...START_UP],
  bootstrap: [AppComponent],
})
export class AppModule {}
